//
//  QYLoadingView.m
//  QiYReader
//
//  Created by 奇阅科技 on 14/12/23.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "QYLoadingView.h"
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
@interface QYLoadingView()
{
    UIImageView *imageView;
}
@property (weak, nonatomic) IBOutlet UIView *animationView;
@end
@implementation QYLoadingView
-(void)awakeFromNib{
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [self layoutSubviews];
    NSArray *myImages = [NSArray arrayWithObjects:
                         [UIImage imageNamed:@"loading11"],
                         [UIImage imageNamed:@"loading22"],
                         [UIImage imageNamed:@"loading33"],nil];
    
    imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, 60, 60)];
    imageView.animationImages = myImages;
    [self.animationView addSubview:imageView];
    self.animationView.layer.cornerRadius = 10;
    imageView.animationDuration = 0.9; //浏览整个图片一次所用的时间
    imageView.animationRepeatCount = 0; // 0 = loops forever 动画重复次数
}
-(void)showView{
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [keyWindow addSubview:self];
    [imageView startAnimating];
}
- (void)closeView{
    [imageView startAnimating];
    [self removeFromSuperview];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    if (self.loadingTouchCancel && [self.delegate respondsToSelector:@selector(loadingViewcancel:)]) {
        [self.delegate loadingViewcancel:self];
    }
}
@end
